button handling
*/
function handleAction(ev) {
- if (ev !== 'stop' &&
- document.getElementById('status') &&
- document.getElementById('status').textContent.substring(0, 6) === 'paused') {
- ev = 'resume';
- }
if (ev === 'restart' || ev === 'reload') {
- let map = document.querySelector('.cbi-map');
+ const map = document.querySelector('.cbi-map');
return dom.callClassMethod(map, 'save')
.then(L.bind(ui.changes.apply, ui.changes))
.then(function () {
+ document.querySelectorAll('.cbi-page-actions button').forEach(function (btn) {
+ btn.disabled = true;
+ btn.blur();
+ });
return fs.exec_direct('/etc/init.d/adblock', [ev]);
})
} else {
+ if (ev !== 'stop') {
+ document.querySelectorAll('.cbi-page-actions button').forEach(function (btn) {
+ btn.disabled = true;
+ btn.blur();
+ });
+ if (document.getElementById('status') &&
+ document.getElementById('status').textContent.substring(0, 6) === 'paused') {
+ ev = 'resume';
+ }
+ }
return fs.exec_direct('/etc/init.d/adblock', [ev]);
}
}
uci.load('adblock')
]);
},
-
render: function (result) {
let m, s, o;
*/
pollData: poll.add(function () {
return L.resolveDefault(fs.read_direct('/var/run/adb_runtime.json'), 'null').then(function (res) {
- var status = document.getElementById('status');
+ const status = document.getElementById('status');
+ const buttons = document.querySelectorAll('.cbi-page-actions button');
try {
var info = JSON.parse(res);
} catch (e) {
status.textContent = '-';
poll.stop();
if (status.classList.contains('spinning')) {
+ buttons.forEach(function (btn) {
+ btn.disabled = false;
+ })
status.classList.remove('spinning');
}
ui.addNotification(null, E('p', _('Unable to parse the runtime information!')), 'error');
}
} else {
if (status.classList.contains("spinning")) {
+ buttons.forEach(function (btn) {
+ btn.disabled = false;
+ })
status.classList.remove("spinning");
if (document.getElementById('btn_suspend')) {
if (status.textContent.substring(0, 6) === 'paused') {
status.textContent = '-';
poll.stop();
if (status.classList.contains('spinning')) {
+ buttons.forEach(function (btn) {
+ btn.disabled = false;
+ })
status.classList.remove('spinning');
}
}
E('button', {
'class': 'btn cbi-button cbi-button-negative important',
'style': 'float:none;margin-right:.4em;',
- 'click': ui.createHandlerFn(this, function () {
+ 'click': function () {
return handleAction('stop');
- })
+ }
}, [_('Stop')]),
E('button', {
'class': 'btn cbi-button cbi-button-apply important',
'style': 'float:none;margin-right:.4em;',
'id': 'btn_suspend',
- 'click': ui.createHandlerFn(this, function () {
+ 'click': function () {
return handleAction('suspend');
- })
+ }
}, [_('Suspend')]),
E('button', {
'class': 'btn cbi-button cbi-button-positive important',
'style': 'float:none;margin-right:.4em;',
- 'click': ui.createHandlerFn(this, function () {
+ 'click': function () {
return handleAction('reload');
- })
+ }
}, [_('Save & Reload')]),
E('button', {
'class': 'btn cbi-button cbi-button-positive important',
'style': 'float:none',
- 'click': ui.createHandlerFn(this, function () {
+ 'click': function () {
handleAction('restart');
- })
+ }
}, [_('Save & Restart')])
])
});